//
//  MyNavgationbar.m
//  杂志看天下
//
//  Created by 秦建英 on 14-2-17.
//  Copyright (c) 2014年 秦建英. All rights reserved.
//

#import "MyNavgationbar.h"

@implementation MyNavgationbar

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}
- (void)createMyNavigationBarWithBackGroundImage:(UIImage *)backgroundImage andTitle:(NSString *)title andLeftBBIImage:(UIImage *)leftBBIImage andLeftBBITitle:(NSString *)leftBBITitle andRightBBIImage:(UIImage *)rightBBIImage andRightBBITitle:(NSString *)rightBBITitle andSEL:(SEL)sel andClass:(id)classObject
{
    [self createBackGroundImageViewWithImage:backgroundImage];
    if(leftBBIImage)
    {
        [self createBBIWithBBIImage:leftBBIImage andBBITitle:leftBBITitle andIsLeft:YES andSEL:sel andClass:classObject];
    }
    if(rightBBIImage)
    {
        [self createBBIWithBBIImage:rightBBIImage andBBITitle:rightBBITitle andIsLeft:NO andSEL:sel andClass:classObject];
    }
}

- (void)createBackGroundImageViewWithImage:(UIImage *)image
{
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    imageView.frame = self.bounds;
    [self addSubview:imageView];
}

- (void)createBBIWithBBIImage:(UIImage *)bbiImage andBBITitle:(NSString *)bbiTitle andIsLeft:(BOOL)isLeft andSEL:(SEL)sel andClass:(id)classObject
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    if(isLeft)
    {
        if(bbiImage)
        {
            btn.frame = CGRectMake(10, 7, bbiImage.size.width, 30);
            btn.titleLabel.font = [UIFont systemFontOfSize:14];
            [btn setBackgroundImage:bbiImage forState:UIControlStateNormal];
            btn.tag = 1;
        }
    }
    else
    {
        if(bbiImage)
        {
            btn.frame = CGRectMake(320-10-bbiImage.size.width, 7, bbiImage.size.width, 30);
            [btn setBackgroundImage:bbiImage forState:UIControlStateNormal];
            btn.titleLabel.font = [UIFont systemFontOfSize:14];
            if(bbiTitle.length>0)
            {
                CGSize titleSize = [bbiTitle sizeWithAttributes:nil];
                btn.frame = CGRectMake(320-30-titleSize.width, 7, titleSize.width+20, 30);
            }
            btn.tag = 2;
        }
    }
    [btn addTarget:classObject action:sel forControlEvents:UIControlEventTouchUpInside];
    [btn setTitle:bbiTitle forState:UIControlStateNormal];
    [self addSubview:btn];
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
